package com.wlb365.admin.modules.schedule.job;

import com.wlb365.admin.common.utils.SdkUtils;
import com.wlb365.admin.modules.constant.JobConstant;
import com.wlb365.admin.modules.schedule.utils.DateUtil;
import com.wlb365.sdk.client.SdkClient;
import com.wlb365.sdk.model.CommonRequest;
import com.wlb365.sdk.model.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 概述：充值提现定时结果查询
 * </p>
 *
 * @author zwh
 * @version 1.0
 * @copyRight 北京微利宝信息技术有限公司  All right reserved.
 * @date 2020/5/25
 */
@Slf4j
@Component
public class RechargeWithdrawJob extends QuartzJobBean {
    /**
     * 每次结果查询条件
     */
    private static int sglReqRecNumFlg = 10;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 获得传入的参数
        String params = jobExecutionContext.getMergedJobDataMap().getString(JobConstant.JOB_MAP_KEY);
        log.info("rechargeWithdrawJob is running star params={}, time:{}", params, new Date());

        //获取sdk客户端
        SdkClient sdkClient = SdkUtils.getClient();

        CommonRequest request = new CommonRequest("zbank.transaction.verify");
        Map<String, Object> bizModel = new HashMap<>();
        bizModel.put("currNum", 0);
        bizModel.put("sglReqRecNumFlg", sglReqRecNumFlg);

        request.setBizModel(bizModel);
        CommonResponse response = sdkClient.execute(request);
        if (!"000000".equals(response.getStatus())) {
            log.info("充值提现对账失败：{}", response.getMsg());
        } else {
            log.info("充值提现对账成功：{}", response.getData());
        }


        log.info("rechargeWithdrawJob is running end params={}, time:{}", params, new Date());
    }
}
